<template>
  <div>
    <van-cell title="搜索历史">
      <div v-if="isDelete">
        <span @click="historys.splice(0)"
              style="margin-right:10px">全部删除</span>
        <span @click="isDelete=false">完成</span>
      </div>
      <van-icon @click="isDelete=true"
                v-else
                name="delete" />
    </van-cell>
    <van-cell @click="onDelete(index,item)"
              v-for="(item, index) in historys"
              :key="item"
              :title="item">
      <van-icon v-show="isDelete"
                name="close" />
    </van-cell>
    <van-empty v-if="!historys.length"
               image="error"
               description="暂无搜索历史" />
  </div>
</template>

<script>
export default {
  data () {
    return {
      isDelete: false
    }
  },
  props: {
    historys: {
      type: Array,
      required: true
    }
  },
  created () {

  },

  methods: {
    onDelete (index, item) {
      if (this.isDelete) {
        this.historys.splice(index, 1)
      } else {
        this.$emit('search', item)
      }
    }
  }
}
</script>

<style scoped lang='less'>
</style>
